package com.lagou.job.controller;

import com.baomidou.mybatisplus.extension.api.R;
import com.lagou.job.service.PositionService;
import com.lagou.job.vo.PositionVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;

/**
 * 职位控制类
 * @author yzh
 */
@RestController
@RequestMapping("position")
public class PositionController {

    @Autowired
    private PositionService positionService;

    /**
     * 获取热点职位列表
     * @return 热点职位列表
     */
    @GetMapping("getHotPosition")
    public R getHotPosition() {
        List<PositionVO> allPosition = null;
        try {
            allPosition = positionService.getHotPosition();
            return R.ok(allPosition);
        } catch (Exception e) {
            e.printStackTrace();
            return R.failed("获取失败");
        }
    }

    /**
     * 获取热点职位详情
     * @return 热点职位详情
     */
    @GetMapping("getPositionDetail/{pId}")
    public R getPositionDetail(@PathVariable Integer pId) {
        PositionVO position = null;
        try {
            position = positionService.getPositionDetail(pId);
            return R.ok(position);
        } catch (Exception e) {
            e.printStackTrace();
            return R.failed("获取失败");
        }
    }
}
